﻿using CPPEI.Coolzon.Designer.UI;
using CPPEI.Coolzon.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CPPEI.Coolzon.Designer.Views
{
    /// <summary>
    /// Interaction logic for DesignView.xaml
    /// </summary>
    public partial class DesignView : View
    {
        private DesignData _designData;

        public DesignView()
        {
            InitializeComponent();

            _ctlMainFrame.IsCanScroll = true;
            _ctlDesignLayoutPartSize.Visibility = System.Windows.Visibility.Hidden;

            _designData = new DesignData(this, _ctlCanvas, this._ctlDesignBorder);

            //this.Content = _ctlRenderPanel;
            //_ctlRenderPanel.EnterDesignMode();
            //_ctlRenderPanel.DesignData.AddPartCompleted += DesignData_AddPartCompleted;
            //_ctlRenderPanel.DesignData.PartSelected += DesignData_PartSelected;

            _ctlDesignBorder.Visibility = System.Windows.Visibility.Hidden;

            this._ctlCanvas.PreviewMouseLeftButtonDown += _ctlCanvas_PreviewMouseLeftButtonDown;
            this._ctlCanvas.PreviewMouseLeftButtonUp += _ctlCanvas_PreviewMouseLeftButtonUp;
            this._ctlCanvas.PreviewMouseMove += _ctlCanvas_PreviewMouseMove;
            this._ctlCanvas.PreviewMouseWheel += _ctlCanvas_PreviewMouseWheel;
            this._ctlCanvas.MouseLeave += _ctlCanvas_MouseLeave;

            this._ctlDesignBorder.SizePointPress += OnDesignBorder_SizePointPress;

            _ctlScrollBarV.Scroll += _ctlScrollBarV_Scroll;
            _ctlScrollBarH.Scroll += _ctlScrollBarH_Scroll;

            this._ctlMainFrame.Zoom += _ctlMainFrame_Zoom;

            // 设置缩放比例下拉框
            _ctlListDesignZoomFactor.SelectionChanged += _ctlListDesignZoomFactor_SelectionChanged;
            for (int index = 1; index <= 20; index++)
            {
                double zoomValue = index * 0.1d;
                ComboBoxItem item = new ComboBoxItem();
                item.Content = string.Format("{0}%", index * 10);
                item.Tag = zoomValue;
                _ctlListDesignZoomFactor.Items.Add(item);
            }
            UpdateUI_ZoomFactorList();
        }

        public void OnSolutionCreated(Metadata.Solution solutionMetdata)
        {
           // _ctlRenderPanel.SetSolution(solutionMetdata);
        }

        public void OnSceneCreated(Metadata.Scene sceneMetadata)
        {
            //_ctlRenderPanel.SwitchToScene(sceneMetadata.Name, null);
        }

        public void OnAreaCreated(Metadata.Area areaMetadata)
        {
        }

        void DesignData_PartSelected(Part part)
        {
            //CPPEI.Coolzon.Designer.UI.EventBus.Instance.SelectPartInstance(part);
        }

        void DesignData_AddPartCompleted(IPartContainer parentPart, Coolzon.UI.Part addedPart)
        {
            //CPPEI.Coolzon.Designer.UI.EventBus.Instance.PartInstanceCreated((IPartContainer)parentPart, addedPart);
        }

        public void OnPartLibItemSelected(Coolzon.Metadata.PartLibItem partLibItem)
        {
            //_ctlRenderPanel.SelectPartItem(partLibItem);
        }


        public void OnPartInstanceCreated(IPartContainer parentPart, Part createdPart)
        {
        }
    }
}
